package util;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

@WebListener
public class LoginUserNumberListener implements HttpSessionAttributeListener {
	
	private int num;
    
	public LoginUserNumberListener() {
    }

	
    public void attributeAdded(HttpSessionBindingEvent arg0)  { 
		ServletContext context = arg0.getSession().getServletContext();
		if ("loginUser".equals(arg0.getName())){
			num++;
			context.setAttribute("loginUserNum",num);
		}
    }

    public void attributeRemoved(HttpSessionBindingEvent arg0)  { 
		ServletContext context = arg0.getSession().getServletContext();
		if ("loginUser".equals(arg0.getName())){
			num--;
			context.setAttribute("loginUserNum", num);
		}

    }

    public void attributeReplaced(HttpSessionBindingEvent arg0)  { 
         // TODO Auto-generated method stub
    }
	
}
